﻿using System;
using System.Transactions;

namespace Ooaavee.TestTools
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public sealed class RollbackTransactionAttribute : TestMethodFeatureBaseAttribute
    {
        private TransactionScope _transaction;

        protected override void OnBeforeTest()
        {
            base.OnBeforeTest();

            _transaction = new TransactionScope(TransactionScopeOption.RequiresNew);
        }

        protected override void OnAfterTest()
        {
            base.OnAfterTest();

            _transaction.Dispose();
        }
    }
}
